package com.shenzhenai.it_hei_ma_threadpoor.a01threadpoor1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author huangzehui
 * @date 2/9/2025 上午12:04 周二
 * @description
 *
 *
 * 多线程&JUC-29-线程池
 * https://www.bilibili.com/video/BV1LG4y1T7n2?spm_id_from=333.788.player.switch&vd_source=e07cc8cc94eb22bd76722071b03cd199&p=29
 */
public class MyThreadPoorDemo {


    public static void main(String[] args) throws InterruptedException {
        /**
         * public static ExecutorService newCachedThreadPool() 创建一个没有上限的线程池
         * public static ExecutorService newFixedThreadPool(int nThreads) 创建有上限的线程池
         */


        // 1. 获取线程池对象
//        ExecutorService pool1 = Executors.newCachedThreadPool();
        ExecutorService pool1 = Executors.newFixedThreadPool(3);


        // 2. 提交任务
        pool1.submit(new MyRunnable());
//        Thread.sleep(1000);

        pool1.submit(new MyRunnable());
//        Thread.sleep(1000);

        pool1.submit(new MyRunnable());
//        Thread.sleep(1000);

        pool1.submit(new MyRunnable());
//        Thread.sleep(1000);

        pool1.submit(new MyRunnable());
//        Thread.sleep(1000);

        pool1.submit(new MyRunnable());
//        Thread.sleep(1000);

        // 3. 销毁线程池
//         pool1.shutdown();
    }
}
